import { list } from "../../../api/customer"

Page({
    data: {
        inputValue: '321',
        options: [],
        placeholder: '请输入电话/名称',
        keyword: '',
        supplierId: '',
        pageNum: 1,
        pageSize: 10
    },
    onLoad() {
        this.getList()
    },
    handleQuery() {
        this.data.options = []
        this.setData({
            options: this.data.options
        })
        this.getList()
    },
    keywordUpdate(e) {
        this.data.keyword = e.detail.value
        this.data.options = []
        this.setData({
            keyword: this.data.keyword,
            options: this.data.options
        })
        this.getList()
    },
    handleQueryClear() {
        this.data.keyword = ""
        this.data.options = []
        this.setData({
            keyword: this.data.keyword,
            options: this.data.options
        })
        this.getList()
    },
    getList() {
        let params = {
            type: 1,
            keyword: this.data.keyword,
            pageNum: this.data.pageNum,
            pageSize: this.data.pageSize
        }
        list(params).then(res => {
            this.setData({
                options: res.data.data
            })
        })
    },
    chooseSeller(e) {
        if (e.currentTarget.dataset.status !== 0 && e.currentTarget.dataset.status !== 2) {
            let pages = getCurrentPages();
            let prevPage = pages[pages.length - 2];
            prevPage.data.supplierId = e.currentTarget.dataset.item.id
            prevPage.setData({
                supplierName: e.currentTarget.dataset.item.name,
                supplierId: prevPage.data.supplierId,
                accoManager: e.currentTarget.dataset.item.linkman,
                phone: e.currentTarget.dataset.item.phone
            });
            wx.navigateBack({
                delta: 1,
            })
        }else{
            if (e.currentTarget.dataset.status === 0) {
                wx.showToast({
                    title:'未认证不能选择',
                    icon:'error'
                })
            }
            if (e.currentTarget.dataset.status === 2) {
                wx.showToast({
                    title:'已驳回不能选择',
                    icon:'error'
                })
            }
            return false
        }

    },
    toAttestation() {
        wx.navigateTo({
            url: '/pages/pagesUser/companyInfo/attestation'
        })
    },
    onPullDownRefresh() {
        this.data.pageNum = 1
        this.data.options = []
        this.setData({
            pageNum: this.data.pageNum,
            options: this.data.options
        })
        this.getList()
        let settime = setTimeout(() => {
            wx.stopPullDownRefresh()
            clearTimeout(settime)
        }, 1000)
    },
    onReachBottom() {
        this.data.pageNum = this.data.pageNum + 1
        this.setData({
            pageNum: this.data.pageNum
        })
        this.getList()
    }

})